function Output_signal = Function_Phy_OFDM_Demodulate_per_Subframe(NSLsymb, NFFT, cpLen0, cpLenR, NRBsc, NSLRB, input_signal, OFDM_Demod_Offset)
%phy_ofdm_demodulate_per_subframe creates frequency-domain signal
%(time-frequency grid) given a time-domain waveform (36.211, 9.9).
% Inputs: 
%   conf: struct containing the following phy configuration related
%   fields: NSLsymb, NFFT, cpLen0, cpLenR, NRBsc
%   input_signal : time-frequency grid

Output_signal_fulllen = zeros(NFFT, 2*NSLsymb);
Output_signal = zeros(NSLRB*NRBsc, 2*NSLsymb);

counter = 1;
for ll = 1 :2*NSLsymb
    if ll == 1 || ll == NSLsymb + 1
        cp = cpLen0;
    else
        cp = cpLenR;
    end
    
    Tmp = input_signal(counter: counter-1+NFFT+cp);
    % Shift by half subcarrier
    Tmp = Tmp.*exp(-2i*pi*(-cp:NFFT-1)'/NFFT/2);
    % Remove CP:
    Tmp = Tmp(cp+1-OFDM_Demod_Offset:end-OFDM_Demod_Offset);
    % FFT
    tmp = fftshift(fft(Tmp));    
    % ------------------------------------------------
    % added by antonis (check with kostas)
    % Normalize power:
    tmp = (1/(NFFT/sqrt(NSLRB*NRBsc)))*tmp;
    % ------------------------------------------------
    Output_signal_fulllen(:, ll) = tmp;
    counter = counter+NFFT+cp;    
    
    % keep useful subcarriers (NRBsc*NSLRB length)
    Output_signal = Output_signal_fulllen(NFFT/2-NSLRB*NRBsc/2+1:NFFT/2+NSLRB*NRBsc/2, :);
            
end